package czr.tetris.frame;

import java.awt.KeyEventPostProcessor;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;

/**
 * 主窗体
 * @author chenzhirong
 *
 */
public class TetrisFrame extends JFrame {

	/**
	 * 唯一序例ID
	 */
	private static final long serialVersionUID = 8025366146836508901L;

	public TetrisFrame(){
		
	}
	
	// 初始化
	public void run() {
		TetrisPanel tetrisPanel = new TetrisPanel();
		tetrisPanel.setSize(800, 1000);
		this.add(tetrisPanel);
		//事件监听  
        this.addKeyListener(tetrisPanel); 
        
		this.setSize(800, 1000);// 设置窗体大小
		this.setTitle("俄罗斯方块");
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);// 设置窗体关闭模式
		this.setLocationRelativeTo(null);// 窗体居中
        this.setVisible(true);  

	
		//关闭窗口
		KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
		manager.addKeyEventPostProcessor(new KeyEventPostProcessor() {
			public boolean postProcessKeyEvent(KeyEvent e) {
				return false;
			}
		});
	}
}
